package hk.m4s.lr.repair.test.ui.goods;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import framework.common.Constant;
import framework.utils.SharedPreferencesUtils;
import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.utils.SharedPreferencesUtil;
import hk.m4s.lr.repair.test.views.InnerGridView;
import okhttp3.Response;

/**
 * Created by qi.wang on 2017/5/10.
 */

public class ScreenActivity extends Activity {
   // private GridsAdapter gridsAdapter;
   // private List<GridModel>list=new ArrayList<>();
    private TextView loctionTx;
    private InnerGridView innerGridView;
    private EditText start_price,end_price;
    private Context context;
    private String brandId="";
    private String minp="";
    private String maxp="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen);
        context=this;
        loctionTx=(TextView)findViewById(R.id.loctionTx);
        innerGridView=(InnerGridView)findViewById(R.id.grid);
        start_price=(EditText)findViewById(R.id.end_price);
        end_price=(EditText)findViewById(R.id.end_price);
        innerGridView.setOnItemClickListener(clickItem);
       // gridsAdapter=new GridsAdapter(context,list);
       // innerGridView.setAdapter(gridsAdapter);
       // findGoodsBrand();
        String city=SharedPreferencesUtils.getSharedPreferences(Constant.pro,"")+ SharedPreferencesUtils.getSharedPreferences(Constant.city,"");
        loctionTx.setText(city);
    }
    public void onClick(View v){
        switch (v.getId()){
            case R.id.selct_canle:
                 finish();
                break;
            case R.id.selct_ok:
                if(start_price.getText().toString().equals("")){
                    minp="";
                }else{
                    minp=start_price.getText().toString();
                }
                if(end_price.getText().toString().equals("")){
                    maxp="";
                }else{
                    maxp=end_price.getText().toString();
                }
                setResult(RESULT_OK,new Intent().putExtra("brandId", brandId).putExtra("minp",minp).putExtra("maxp",maxp));
                finish();
                break;
            case R.id.leftLayout:
                  finish();
                break;
        }

    }
    AdapterView.OnItemClickListener clickItem = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                long arg3) {
            // TODO Auto-generated method stub
        //    GridModel model=list.get(arg2);
//            if(model.getSelect().equals("1")){
//                model.setSelect("2");
//                gridsAdapter.list.set(arg2,model);
//            }else if(model.getSelect().equals("2")){
//                model.setSelect("1");
//                gridsAdapter.list.set(arg2,model);
//            }
         //   gridsAdapter.flag=arg2;
          //  brandId=model.getBid();
          //  gridsAdapter.notifyDataSetChanged();
        }

    };
//    public void findGoodsBrand() {
//        Map<String, Object> parmas = new HashMap<>();
//        parmas.put("device_type", Constant.device_type);
//        parmas.put("userId", SharedPreferencesUtils.getSharedPreferences(Constant.userId, ""));
//        parmas.put("token", SharedPreferencesUtils.getSharedPreferences(Constant.token, ""));
//        AccountSerive.findGoodsBrand(context, parmas, new ResponseCallback<GridModel>() {
//            @Override
//            public void onSuccess(GridModel userinfoModel) {
//                list.clear();
//                if(userinfoModel.getList()!=null){
//                    list.addAll(userinfoModel.getList());
//                    gridsAdapter.notifyDataSetChanged();
//                }
//            }
//
//            @Override
//            public void onError(Response response, int errorCode, String errorMsg, Exception e) {
//
//            }
//        });
//
//    }
}
